package com.sc.sc250601.cook.controller;

import com.sc.sc250601.cook.pojo.Result;
import com.sc.sc250601.cook.pojo.SalesRankDTO;
import com.sc.sc250601.cook.pojo.Snack;
import com.sc.sc250601.cook.service.SnackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/snack")
public class SnackController {

    @Autowired
    private SnackService snackService;

    /**
     * 查询最新商品(每日上新)
     * @return
     */
    @RequestMapping("/dayNew")
    public Result dayNew(){
        List<Snack> snacks = snackService.dayNew();
        if(snacks.isEmpty()) {
            return new Result(0, "暂无新商品");
        }
        return new Result(1, "查询成功", snacks);
    }

    /**
     * 查询本周热销商品
     * @return
     */
    @RequestMapping("/weekTop")
    public Result weekTop(){
        List<SalesRankDTO> snacks = snackService.weekTop();
        if(snacks.isEmpty()) {
            return new Result(0, "暂无商品");
        }
        return new Result(1, "查询成功", snacks);
    }
}
